<?php
namespace Supplier\Controller;
use Think\Controller;
use Think\Auth;
use Think\Model;
class CommonController extends Controller{
	public function _initialize(){
		//验证登录
// var_dump($_SESSION['supplier']);die;		
        
        if(empty($_SESSION['supplier'])){
			$this->redirect("Login/index");
			exit();

		}

		if(!empty($_SESSION['supplier'])){

			$jilu =  $_SESSION;
		foreach($jilu as $key => $value){
			$id = $value['id'];
		}
		
		$auth=new \Think\Auth();
		$rule_name=MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
	
		$result=$auth->check($rule_name,$id);



		// if(!$result){
		// 	$this->error('您没有权限访问');
			
		// }

		}
		


		// print_r($_SESSION);
		// echo $rule_name;

		




	}

	

	public function uploadFace() {
        //if (!$this->isPost()) {
        //	$this->error('页面不存在');
        //}
        //echo 'asdfsaf';die;

        // print_r($_POST);
        // die();
        $upload = $this->_upload('Pic');
        $this->ajaxReturn($upload);
    }
    Private function _upload ($path) {

        //{"error":"0","pic":"Uploads\/149285834358625.jpg","name":"149285834358625.jpg"}
        //import('ORG.Net.UploadFile');	//引入ThinkPHP文件上传类
        $upload = new \Think\Upload();	//实例化上传类
        $upload->rootPath = './Uploads/';
		$upload->savePath = '';
		$upload->saveName = array('uniqid','');
		$upload->exts     = array('jpg', 'gif', 'png', 'jpeg');
		$upload->autoSub  = true;
		$upload->subName  = array('date','Ym');
        //$obj->upload();die;
        $info   =   $upload->upload();
        if (!$info) {
            return array('status' => 0, 'msg' => $upload->getError());
        } else {
            foreach($info as $file){
                $pic = $file['savepath'].$file['savename'];
            }
            //$pic =  $info[0][savename];
            //echo $pic;die;
            return array(
                'error' => 0,
                'pic' => "/Uploads/".$pic,
                'name'=>$file['savename']
            );
        }
    }


//商品分类
    public function allCategory($field='*'){  
        return D('Terms')->field($field)->select();  
    } 
    //创建组织结构分类树（即无限极分类） 
    public function tree(&$list,$pid=0,$level=0,$html='&nbsp;&nbsp;&nbsp;&nbsp;'){  
        static $tree = array();  
        foreach($list as $v){  
            if($v['parent_id'] == $pid){  
                $v['html'] = str_repeat($html,$level);  
                $tree[] = $v;  
                $this->tree($list,$v['term_id'],$level+1);  
            }  
        }  
        return $tree;  
    }  




}

?>